package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.dao.OrderDao;
import com.atguigu.springcloud.domain.Order;
import com.atguigu.springcloud.service.AccountService;
import com.atguigu.springcloud.service.OrderService;
import com.atguigu.springcloud.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private AccountService accountService;
    @Autowired
    private StorageService storageService;
    @Override
    public void create(Order order) {
        log.info("-----创建订单");
        orderDao.create(order);
        log.info("-----创建完成");

        log.info("-----开始减库存");
        storageService.decrease(order.getProductId(),order.getCount());
        log.info("-----减少库存结束");

        log.info("-----开始减少余额");
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("-----减少余额结束");

        log.info("------修改订单状态");
        orderDao.update(order.getUserId(),order.getStatus());
    }
}
